package com.bjsxt.set1;

public class Student implements Comparable<Student>{
    private String name;
    private String sex;
    private int age;
    private double score;

    @Override
    public int compareTo(Student other) {
        return this.name.compareTo(other.name);
        //return this.age - other.age;
    }

    public Student() {
    }

    public Student(String name, String sex, int age, double score) {
        this.name = name;
        this.sex = sex;
        this.age = age;
        this.score = score;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getSex() {
        return sex;
    }

    public void setSex(String sex) {
        this.sex = sex;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public double getScore() {
        return score;
    }

    public void setScore(double score) {
        this.score = score;
    }

    @Override
    public boolean equals(Object o) {
        //比较地址
        if (this == o) return true;
        //比较是否属于同一种对象类型或者传入对象类型为空
        if (o == null || getClass() != o.getClass()) return false;

        //强行转换为本类型
        Student student = (Student) o;

        //判断年龄是否相等
        if (age != student.age) return false;
        //如果两者不等于0说明两者不相等
        if (Double.compare(student.score, score) != 0) return false;
        //如果名字不等于空则判断名称是否等于当前名称，并且取反
        if (name != null ? !name.equals(student.name) : student.name != null) return false;

        return sex != null ? sex.equals(student.sex) : student.sex == null;
    }

    @Override
    public int hashCode() {
        int result;
        long temp;
        result = name != null ? name.hashCode() : 0;
        result = 31 * result + (sex != null ? sex.hashCode() : 0);
        result = 31 * result + age;
        temp = Double.doubleToLongBits(score);
        result = 31 * result + (int) (temp ^ (temp >>> 32));
        return result;
    }

    @Override
    public String toString() {
        return "Student{" +
                "name='" + name + '\'' +
                ", sex='" + sex + '\'' +
                ", age=" + age +
                ", score=" + score +
                '}';
    }
}
